function gadget:GetInfo()
  return {
    name      = "Collision volumes",
    desc      = "Adds a button to unit that allows to switch between its weapons",
    author    = "Rafal",
    date      = "Aug 2011",
    license   = "GNU GPL, v2 or later",
    layer     = 0,
    enabled   = true  --  loaded by default?
  }
end

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------

if (not gadgetHandler:IsSyncedCode()) then
  return
end
-- SYNCED

--------------------------------------------------------------------------------

local spGetUnitDefID = Spring.GetUnitDefID
local spGetUnitPieceMap = Spring.GetUnitPieceMap
local spSetPieceCollisionVolume = Spring.SetUnitPieceCollisionVolumeData

--------------------------------------------------------------------------------

local OFFSETZ = 6
local AXIS = 9
local DISABLED = 10

local defsToSet = {}  -- used one time per UnitDef


for id, ud in ipairs(UnitDefs) do
  if (ud.myCustomParams.usePieceCollisionVolumes) then
    defsToSet[id] = true
  end
end

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------

function gadget:Initialize()
	local units = Spring.GetAllUnits()
	for i = 1, #units do
		local udID = spGetUnitDefID(units[i])
            --defsToSet[udid] = true
		gadget:UnitCreated(units[i], udID)
	end
end

--VFS.Include("luarules/utils/debug.lua")
function gadget:UnitCreated(unitID, unitDefID, unitTeam, builderID)
  if (defsToSet[unitDefID]) then
    --Spring.Echo("UnitCreated: " .. UnitDefs[unitDefID].name)
    
    -- local colVolData = { Spring.GetUnitPieceCollisionVolumeData(unitID, i) }
    -- if (colVolData[DISABLED] == false) then
      -- colVolData[OFFSETZ] = colVolData[OFFSETZ] + 12.6638
      -- colVolData[8] = colVolData[AXIS]
      -- colVolData[9] = nil
      -- colVolData[10] = nil
      -- spSetPieceCollisionVolume(unitID, i, true, true, true, true, unpack(colVolData))
    -- end
    
    --local ud = UnitDefs[unitDefID]
    --Spring.Echo (tostring(ud.midx) .. " " .. tostring(ud.midy) .. " " .. tostring(ud.midz))

    local pieces = spGetUnitPieceMap(unitID)
    local colVols = UnitDefs[unitDefID].myCustomParams.collisionVolumes
    if (type(colVols) == "table") then
      for pieceName, cv in pairs(colVols) do
        if (type(cv) == "table") then
          local pieceID = pieces[pieceName]
          if (pieceID) then
            local scale  = (type(cv.scale ) == "table") and cv.scale  or { 1, 1, 1 }
            local offset = (type(cv.offset) == "table") and cv.offset or { 0, 0, 0 }
            
            spSetPieceCollisionVolume(
              unitID, pieceID - 1, true, true, true, true,
              scale[1], scale[2], scale[3], offset[1], offset[2], offset[3],
              cv.type, cv.axis
            )
          else
            Spring.Echo('[unit_collision_volumes.lua] Error: UnitDef "' .. UnitDefs[unitDefID].name .. '" has no piece of name "' .. pieceName .. '"')
          end
        end
      end
    end
    --for n, p in pairs(pieces) do printTable ("GetUnitPieceCollisionVolumeData(" .. n .. ")", { Spring.GetUnitPieceCollisionVolumeData(unitID, p - 1) }) end
    
    defsToSet[unitDefID] = nil
  end
end

-- SYNCED